home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Software Contest 3
/
FM Towns Software Contest 3.iso
/
exp
/
bpp
/
no1
/
pi.bpp
< prev
next >
Wrap
Text File
|
1994-01-07
|
2KB
|
80 lines
'
' 分割統治法により円周率を求める
' 参考文献 Cマガジン92年10月号
' 実践アルゴリズム戦略 解法のテクニック(松田 晋)
'
#define SCALE 320
clear ,,4096 ' スタックを大きめに設定しておく
defdbl a-z
makestack 0,1024,0,1024
call main
end
sub square(x,y,length,fill%)
local x0%, y0%, x1%, y1%
x0%=x*SCALE
y0%=y*SCALE
x1%=(x+length)*SCALE
y1%=(y+length)*SCALE
if fill% then
call boxfill(x0%,y0%,x1%,y1%)
else
call box(x0%,y0%,x1%,y1%)
endif
endsub
sub area(bybody r,x,y,length)
local r1,r2,r3,r4
if x^2+y^2>1.0 then
call square(x,y,length,0)
r=0.0
exitsub
elseif (x+length)^2+(y+length)^2<1.0 then
call square(x,y,length,1)
r=length^2
exitsub
elseif length<=eps then
call square(x,y,length,0)
r=length^2*0.5
exitsub
else
length=length*0.5
call area(r1,x,y,length)
call area(r2,x,y+length,length)
call area(r3,x+length,y,length)
call area(r4,x+length,y+length,length)
r=r1+r2+r3+r4
exitsub
endif
endsub
sub main
local pi
input "許容誤差 ";eps
call initgraph
call circleedge(0,0,SCALE)
call area(pi,0,0,1.0)
pi=pi*4
print "π=";pi
endsub
sub initgraph
cls
endsub
sub box(x0%,y0%,x1%,y1%)
line(x0%,y0%)-(x1%,y1%),pset,7,b
endsub
sub boxfill(x0%,y0%,x1%,y1%)
line(x0%,y0%)-(x1%,y1%),pset,1,bf
line(x0%,y0%)-(x1%,y1%),pset,7,b
endsub
sub circleedge(x%,y%,r%)
circle(x%,y%),r%
endsub